/*!
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *    Author: flareguner
 *    E-Mail: flareguner@gmail.com
 *    Years: 2010-2011
 */

#include "dictionaryconfig.h"
#include "src/platform.h"
#include <QtGui/QCheckBox>
#include <QtGui/QVBoxLayout>
#include <QtCore/QSettings>
#include <QtCore/QEvent>


const bool DictionaryConfig::m_default_show_details = true;


DictionaryConfig::DictionaryConfig(QWidget *parent) :
    QWidget(parent)
{
    createUi();
    settings = new QSettings(Platform::getOrganizationName(),
                             Platform::getApplicationName());
    settings->beginGroup("Dictionary");
}

DictionaryConfig::~DictionaryConfig() {
    settings->endGroup();
    delete showDetail, mainLayout, settings;
}

void DictionaryConfig::save() {
    settings->setValue("showDetails", showDetail->isChecked());
    settings->setValue("showDetailsInTooltip", showDetailInTooltip->isChecked());


}
void DictionaryConfig::read(){
    showDetail->setChecked(settings->value("showDetail", true).toBool());
    showDetailInTooltip->setChecked(settings->value("showDetailsInTooltip", true).toBool());

}
void DictionaryConfig::truncate(){
    showDetail->setChecked(m_default_show_details);
}

bool DictionaryConfig::getShowDetails() const {
    return showDetail->isChecked();
}

bool DictionaryConfig::getShowDetailsInToolTip() const {
    return showDetailInTooltip->isChecked();
}

void DictionaryConfig::changeEvent(QEvent *e) {
    if(e->type() == QEvent::LanguageChange) {
        showDetail->setText(QCheckBox::tr("Show details"));
        showDetailInTooltip->setText(QCheckBox::tr("Show details in ToolTip"));
        showDetail->setToolTip(QCheckBox::tr("Show dictionary detail in primary field if single word entered"));
        showDetail->setToolTip(QCheckBox::tr("Show dictionary detail also in translation tooltip"));

    }
}

void DictionaryConfig::createUi() {
    showDetail = new QCheckBox(this);
    showDetailInTooltip = new QCheckBox(this);
    mainLayout= new QVBoxLayout;
    mainLayout->addWidget(showDetail);
    mainLayout->addWidget(showDetailInTooltip);
    mainLayout->addStretch();
    this->setLayout(mainLayout);
}
